<template>
  <!-- 账户变动审核 -->
  <div>
    <!-- 头部查询部分 -->
    <div class="header">
      <el-date-picker
        v-model="Time"
        type="datetimerange"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        align="right"
      />
      <!-- 收益状态下拉选择框 -->
      <el-select v-model="Applytype" clearable placeholder="请选择状态">
        <el-option label="提现" value="提现" />
        <el-option label="充值" value="充值" />
      </el-select>
      <!-- 审核下拉选择框 -->
      <el-select v-model="Certstatus" clearable placeholder="请选择状态">
        <el-option label="通过" value="通过" />
        <el-option label="不通过" value="不通过" />
        <el-option label="未审核" value="未审核" />
      </el-select>
      <!-- 申请人编号输入框 -->
      <el-input
        v-model="userid"
        placeholder="请输入申请人编号"
        style="width: 240px"
        clearable
      />
      <!-- 查询按钮 -->
      <el-button type="success" @click="choose">查询</el-button>
    </div>
    <!-- 表格数据展示区 -->
    <div class="table_content">
      <el-table :data="AccountList" style="width: 100%">
        <!-- 序号 -->
        <el-table-column type="index" label="序号" align="center" />
        <!-- 申请人编号 -->
        <el-table-column prop="userId" label="申请人编号" align="center" />
        <!-- 申请时间 -->
        <el-table-column prop="applyTime" label="申请时间" align="center">
          <template slot-scope="scope">
            <span>{{
              moment(scope.row.applyTime).format("YYYY-MM-DD HH:mm:SS")
            }}</span>
          </template>
        </el-table-column>
        <!-- 变更类型 -->
        <el-table-column prop="applyType" label="变更类型" align="center" />
        <!-- 变更资金 -->
        <el-table-column label="变更资金" align="center">
          <template slot-scope="scope">
            ￥<span style="color:red;font-size:25px">
              {{ scope.row.money }}
            </span>元
          </template>

        </el-table-column>
        <!-- 变更原因 -->
        <el-table-column prop="reason" label="变更原因" align="center" />
        <!-- 状态 -->
        <el-table-column label="状态" show-overflow-tooltip align="center">
          <template slot-scope="scope">
            <el-tag
              v-if="scope.row.status == '通过'"
              size="small"
              type="success"
            >
              {{ scope.row.status }}
            </el-tag>
            <el-tag
              v-else-if="scope.row.status == '不通过'"
              size="small"
              type="danger"
            >
              {{ scope.row.status }}
            </el-tag>
            <el-tag
              v-else-if="scope.row.status == '未审核'"
              size="small"
              type="info"
            >
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.status=='未审核'">
              <el-button type="text" size="small" style="color:#E6A23C" @click="handleClick(scope.row.id)">撤销</el-button>
              <el-button type="text" size="small" style="color:#67C23A" @click="checkpass(scope.row.id)">通过</el-button>
              <el-button type="text" size="small" style="color:#F56C6C" @click="checknopass(scope.row.id)">不通过</el-button>
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 尾部分页查询 -->
    <div class="footer">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[2, 4, 6, 8]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { get, post } from '@/utils/request'
import { log } from '@antv/g2plot/lib/utils'
const moment = require('moment')
export default {
  data() {
    return {
      // 日历
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      // 变更类型下拉框
      Applytype: '',
      // 审核状态下拉框
      Certstatus: '',
      // 申请人编号
      userid: '',
      // 查询时间数组
      Time: [],
      // 页面展示数据的总条数
      total: 10,
      // 当前页码
      currentPage: 1,
      // 每页要展示的数据
      pageSize: 8,
      // 表格数据展示数组
      AccountList: [],
      // 查询审核信息对象
      AccountData: {}
    }
  },
  computed: {},
  created() {
    this.getAllaccountData()
  },
  mounted() {},
  methods: {
    // 时间戳装换方法
    moment,
    // 发送网络请求拿到全部账户信息
    async getAllaccountData() {
      const data = {
        page: this.currentPage,
        pageSize: this.pageSize
      }
      const res = await get('/accountApply/pageQueryAccountApply', { ...data, ...this.AccountData })
      this.AccountList = res.data.list
      this.total = res.data.total
    //   console.log(res);
    },

    // 每页展示的数据条数
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getAllaccountData()

      //   console.log(`每页 ${val} 条`);
    },

    // 控制当前页的页数
    handleCurrentChange(val) {
      this.currentPage = val
      this.getAllaccountData()
      // console.log(`当前页: ${val}`);
    },

    // 查询按钮方法
    choose() {
      if (!this.Time) {
        var data = {
        // 开始时间时间
          beginTime: '',
          // 结束时间
          endTime: '',
          // 审核状态
          status: this.Certstatus,
          // 申请人编号
          userId: this.userid,
          // 变更类型
          applyType: this.Applytype
        }
      } else {
        var data = {
        // 开始时间时间
          beginTime: Date.parse(this.Time[0]),
          // 结束时间
          endTime: Date.parse(this.Time[1]),
          // 审核状态
          status: this.Certstatus,
          // 申请人编号
          userId: this.userid,
          // 变更类型
          applyType: this.Applytype
        }
      }

      // 格式化参数 当某个属性没有值的时候将其删除 以防影响网络请求的操作
      for (const key in data) {
        if (!data[key]) {
          delete data[key]
        }
      }
      this.AccountData = data
      this.currentPage = 1
      this.getAllaccountData()
    },

    // 根据id撤销账户申请
    async handleClick(id) {
      const res = await get('/accountApply/revokeAccountApply', { id })
      if (res.status == 200) {
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: res.message,
          type: 'danger'
        })
      }
      // 刷新页面
      this.getAllaccountData()
    },

    // 根据id给用户账户审核通过
    async checkpass(id) {
      const res = await get('/accountApply/checkPass', { id })
      if (res.status == 200) {
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: res.message,
          type: 'danger'
        })
      }
      // 刷新页面
      this.getAllaccountData()
    },

    // 根据id给用户账户审核不通过通过
    async checknopass(id) {
      const res = await get('/accountApply/checkNoPass', { id })
      if (res.status == 200) {
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: res.message,
          type: 'danger'
        })
      }
      // 刷新页面
      this.getAllaccountData()
    }

  }
}
</script>
<style scoped>
/* 分页区域的样式 */
.footer {
  position: fixed;
  bottom: 40px;
  right: 10px;
}
</style>
